<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 

mm_showMyFileName( __FILE__ );

require_once( CLASSPATH . "ps_search_pos.php" );
require_once( CLASSPATH . "htmlTools.class.php" );

$location = JRequest::getString("txtLocation", "");
$hungry = JRequest::getString("txtHungry", "");
$arrVendors = ps_search_pos::getRestaurantList(0, $location, $hungry);
?>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $GLOBALS['MAP_GOOGLE_KEY']; ?>" type="text/javascript"></script>
<script src="libraries/googlemap/js/GoogleFuncs.js" type="text/javascript"></script>
<table cellpadding="1" cellspacing="2" border="0" width="100%">
    <tr>
        <td width="50%" style="border-right: solid 1px #999999;" valign="top">
            <div style="color: #000; font-weight: bold;">
                <?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_DESC') ?>
            </div>
            <div>
            <table cellpadding="0" cellspacing="0" border="0" width="98%" style="color: #000; margin-top: 10px;">
                <tr style="font-weight: bold;">
                    <td width="5%"></td>
                    <td width="40%" align="left"><?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_RESTAURANT') ?></td>
                    <td width="20%" align="left"><?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_KEYWORD') ?></td>
                    <td width="20%" align="left"><?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_DELIVERY') ?></td>
                    <td width="15%" align="left"><?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_FAVORITE') ?></td>
                </tr>
                <?php 
                $bgTmp = "background-color: #CCCCCC;";
                $row_count = count($arrVendors['vendors']);
                for ($n = 0; $n < $row_count; $n++) {
                    $bg = ($n%2 == 0) ? $bgTmp : "";
                    $obj = $arrVendors['vendors'][$n];
                ?>
                <tr style="<?php echo $bg; ?>">
                    <td align="right"><?php echo ($n + 1); ?>.&nbsp;</td>
                    <td style="color: #CC0000; font-weight: bold;"><a href="<?php echo $sess->purl( $mm_action_url."index.php?option=com_virtuemart&page=shop.browse&vendor_id=".$obj['vendor_id']); ?>" style="color: #CC0000;"><?php echo $obj['vendor_name']; ?></a></td>
                    <td align="center"><?php echo $obj['vendor_keyword']; ?></td>
                    <td align="center"><?php echo $obj['vendor_delivery']; ?></td>
                    <td align="center"></td>
                </tr>
                <tr style="<?php echo $bg; ?>">
                    <td></td>
                    <td colspan="4">
                    <?php 
                        echo $obj['vendor_address_1']; 
                        if($obj['vendor_address_2']!='')
                            echo ', '.$obj['vendor_address_2'];
                        if($obj['vendor_city']!='')
                            echo ', '.$obj['vendor_city'];
                        if($obj['vendor_state']!='')
                            echo ', '.$obj['vendor_state'];
                        if($obj['vendor_zip']!='')
                            echo ', '.$obj['vendor_zip'];
                        if($obj['vendor_phone']!='')
                            echo ', '.$obj['vendor_phone'];
                    ?>                    
                    </td>
                </tr>
                <tr style="<?php echo $bg; ?>">
                    <td></td>
                    <td colspan="4"><?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_CUISINE') ?>: <?php echo $obj['vendor_cuisine']; ?></td>
                </tr>
                <tr style="<?php echo $bg; ?>">
                    <td align="right"></td>
                    <td colspan="4">                        
                        <?php
                            require_once( CLASSPATH . 'ps_product_category.php' );   
                            $category_id= ps_product_category::getCategoryId($obj['vendor_id']); 
                            include( "modules/mod_virtuemart_featureprod/mod_virtuemart_featureprod.php" );
                        ?>
                    </td>                    
                </tr>
                <?php } ?>
            </table>
            </div>
        </td>
        <td width="50%" style="border-left: solid 1px #999999;" valign="top" align="center">
            <div id="map" style="width: 370px; height: 300px"></div>
            <table cellpadding="0" cellspacing="0" border="0" width="370px" style="margin-top: 5px; color: #666666;">
                <tr style="background-color: #CCCCCC;">
                    <td style="font-weight: bold; width: 80px;">&nbsp;&nbsp;<?php echo $VM_LANG->_('PHPSHOP_SEARCH_POS_RADIUS') ?>:</td>
                    <td>
                        <input type="radio" name="miles_group" id="5miles" checked="checked" value="5" onclick="_GoogleMaps_.radiusChanged(5)"/>
                        <label for="5miles">5 miles</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="miles_group" id="10miles" value="10" onclick="_GoogleMaps_.radiusChanged(10)"/>
                        <label for="10miles">10 miles</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="miles_group" id="15miles" value="15" onclick="_GoogleMaps_.radiusChanged(15)"/>
                        <label for="15miles">15 miles</label>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<script language="javascript">
<?php echo $arrVendors['address']; ?>

function initSearchPos() {
    var address = $('txtLocation').value;
    var radius = 5;
    
    _GoogleMaps_.init(address, radius);
}
window.onload = initSearchPos;
window.onunload = GUnload;
</script>